using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_City {
		#region Fields
		private int iD;
		private int cityID;
		private string cityName;
		private int countryID;
		private int provinceID;
		private string ipAddressL;
		private string ipAddressH;
		private int lanuageId;
		private string description;
		private string locCode;
		private string name;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_City class.
		/// </summary>
		public TF_City() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_City class.
		/// </summary>
		public TF_City(int cityID, string cityName, int countryID, int provinceID, string ipAddressL, string ipAddressH, int lanuageId, string description, string locCode, string name) {
			this.cityID = cityID;
			this.cityName = cityName;
			this.countryID = countryID;
			this.provinceID = provinceID;
			this.ipAddressL = ipAddressL;
			this.ipAddressH = ipAddressH;
			this.lanuageId = lanuageId;
			this.description = description;
			this.locCode = locCode;
			this.name = name;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_City class.
		/// </summary>
		public TF_City(int iD, int cityID, string cityName, int countryID, int provinceID, string ipAddressL, string ipAddressH, int lanuageId, string description, string locCode, string name) {
			this.iD = iD;
			this.cityID = cityID;
			this.cityName = cityName;
			this.countryID = countryID;
			this.provinceID = provinceID;
			this.ipAddressL = ipAddressL;
			this.ipAddressH = ipAddressH;
			this.lanuageId = lanuageId;
			this.description = description;
			this.locCode = locCode;
			this.name = name;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the ID value.
		/// </summary>
		public int ID {
			get { return iD; }
			set { iD = value; }
		}
		
		/// <summary>
		/// Gets or sets the CityID value.
		/// </summary>
		public int CityID {
			get { return cityID; }
			set { cityID = value; }
		}
		
		/// <summary>
		/// Gets or sets the CityName value.
		/// </summary>
		public string CityName {
			get { return cityName; }
			set { cityName = value; }
		}
		
		/// <summary>
		/// Gets or sets the CountryID value.
		/// </summary>
		public int CountryID {
			get { return countryID; }
			set { countryID = value; }
		}
		
		/// <summary>
		/// Gets or sets the ProvinceID value.
		/// </summary>
		public int ProvinceID {
			get { return provinceID; }
			set { provinceID = value; }
		}
		
		/// <summary>
		/// Gets or sets the IpAddressL value.
		/// </summary>
		public string IpAddressL {
			get { return ipAddressL; }
			set { ipAddressL = value; }
		}
		
		/// <summary>
		/// Gets or sets the IpAddressH value.
		/// </summary>
		public string IpAddressH {
			get { return ipAddressH; }
			set { ipAddressH = value; }
		}
		
		/// <summary>
		/// Gets or sets the LanuageId value.
		/// </summary>
		public int LanuageId {
			get { return lanuageId; }
			set { lanuageId = value; }
		}
		
		/// <summary>
		/// Gets or sets the Description value.
		/// </summary>
		public string Description {
			get { return description; }
			set { description = value; }
		}
		
		/// <summary>
		/// Gets or sets the LocCode value.
		/// </summary>
		public string LocCode {
			get { return locCode; }
			set { locCode = value; }
		}
		
		/// <summary>
		/// Gets or sets the Name value.
		/// </summary>
		public string Name {
			get { return name; }
			set { name = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_City table.
		/// </summary>
		public void Insert() {
			iD = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_CityInsert", cityID, cityName, countryID, provinceID, ipAddressL, ipAddressH, lanuageId, description, locCode, name));
		}
		
		/// <summary>
		/// Updates a record in the TF_City table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_CityUpdate", iD, cityID, cityName, countryID, provinceID, ipAddressL, ipAddressH, lanuageId, description, locCode, name);
		}
		
		/// <summary>
		/// Deletes a record from the TF_City table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_CityDelete", iD);
		}
		
		/// <summary>
		/// Selects a single record from the TF_City table.
		/// </summary>
		public static TF_City Select(int iD) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_CitySelect", iD)) {
				if (dataReader.Read()) {
					return MakeTF_City(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_City table.
		/// </summary>
		public static List<TF_City> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_CitySelectAll")) {
				List<TF_City> tF_CityList = new List<TF_City>();
				while (dataReader.Read()) {
					TF_City tF_City = MakeTF_City(dataReader);
					tF_CityList.Add(tF_City);
				}
				return tF_CityList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_City class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_City MakeTF_City(SqlDataReader dataReader) {
			TF_City tF_City = new TF_City();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_City.ID = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_City.CityID = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_City.CityName = dataReader.GetString(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_City.CountryID = dataReader.GetInt32(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_City.ProvinceID = dataReader.GetInt32(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tF_City.IpAddressL = dataReader.GetString(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tF_City.IpAddressH = dataReader.GetString(6);
			}
			if (dataReader.IsDBNull(7) == false) {
				tF_City.LanuageId = dataReader.GetInt32(7);
			}
			if (dataReader.IsDBNull(8) == false) {
				tF_City.Description = dataReader.GetString(8);
			}
			if (dataReader.IsDBNull(9) == false) {
				tF_City.LocCode = dataReader.GetString(9);
			}
			if (dataReader.IsDBNull(10) == false) {
				tF_City.Name = dataReader.GetString(10);
			}

			return tF_City;
		}
		#endregion
	}
}
